$(function () {
    $("body").on("click","#save-back",function () {
       saveLinkConfig(1);
    }).on("click","#save-continue",function () {
       saveLinkConfig(2);
    }).on("click","#cancel",function () {
        var linkType = $("input[name='linkType']").val();
        window.location.href=baseloaction+'/admin/manage/link/linkConfigList?linkType='+linkType;
    });

    /**
     * 保存链接配置方法
     * @param type 保存成功手的操作类型，1保存并返回，2保存后继续添加
     */
    function saveLinkConfig(type) {
        var params = $("#commentForm").serializeJSON();
        params = JSON.stringify(params);
        $.ajax({
            url: baseloaction + '/admin/manage/link/saveLinkConfig',
            type:'post',
            dataType:'json',
            data:params,
            contentType:'application/json;charset=utf-8',
            success:function (result) {
                icModale(0, result.message);
                if(result.success==true){
                    var linkType = $("input[name='linkType']").val();
                    var parentId = $("input[name='parentId']").val();
                    if(type==1){
                        window.location.href=baseloaction+'/admin/manage/link/linkConfigList?linkType='+linkType;
                    }
                    if(type==2){
                        window.location.href=baseloaction+'/admin/manage/link/initAdd?parentId='+parentId+'&linkType='+linkType;
                    }
                }
            },
            error:function () {
                icModale(0, '系统错误，链接配置保存失败');
            }
        });
    }
});
